﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DevExpress.Utils;
using DevExpress.XtraEditors;
namespace DataAccess
{
    public class DataConnection
    {
        public static string connectionString = null;
        protected static SqlConnection connection = null;
        protected static void CreateConnectionString()
        {

            connectionString = @"Data Source=CLOUDS-LAP;Initial Catalog=QLDaiLy;Integrated Security=True";
            connection = new SqlConnection(connectionString);
        }
        protected static void OpenConnection()
        {
            CreateConnectionString();
            connection = new SqlConnection(connectionString);
            connection.Open();
        }
        protected static void CloseConnection()
        {
            CreateConnectionString();
            if (connection != null)
                connection.Close();
        }
        public static DataTable ExecQuery(string s)
        {
            CreateConnectionString();
            SqlDataAdapter adapter = new SqlDataAdapter(s, connection);
            DataTable dt = new DataTable();
            adapter.Fill(dt);
            return dt;
        }
        public static void ExecNonQuery(string s)
        {
            CreateConnectionString();
            OpenConnection();
            SqlCommand cmd = new SqlCommand(s, connection);
            cmd.ExecuteNonQuery();
            CloseConnection();
        }
        public static object ExecScalar(string s)
        {
            CreateConnectionString();
            OpenConnection();
            SqlCommand cmd = new SqlCommand(s, connection);
            cmd.CommandText = s;
            return cmd.ExecuteScalar();
        }
        
    }
    public class ControlLocalizer : DevExpress.XtraEditors.Controls.Localizer
    {

        public ControlLocalizer() : base() { }

        public override string GetLocalizedString(DevExpress.XtraEditors.Controls.StringId id)
        {
            if (id == DevExpress.XtraEditors.Controls.StringId.XtraMessageBoxYesButtonText)
                return "Đồng ý";
            if (id == DevExpress.XtraEditors.Controls.StringId.XtraMessageBoxNoButtonText)
                return "Hủy bỏ";
            if (id == DevExpress.XtraEditors.Controls.StringId.XtraMessageBoxOkButtonText)
                return "Đồng ý";
            return base.GetLocalizedString(id);
        }
    }
    
}
